﻿using System;
using System.Data;
using MySql.Data.MySqlClient;

namespace PDFDesign.Repository.Builder
{
    public class MYSQLDbConnectionBuilder : IDbConnectionBuilder
    {
        private string _connStr;

        public MYSQLDbConnectionBuilder(string connStr)
        {
            _connStr = connStr;
        }

        /// <summary>
        /// 获取SqlConnection连接对象
        /// </summary>
        public IDbConnection DbConnection
        {
            get
            {
                IDbConnection conn = null;
                try
                {
                    conn = new MySqlConnection(_connStr);
                    conn.Open();
                }
                catch (Exception ex)
                {
                    if (null != conn)
                    {
                        conn.Dispose();
                        conn = null;
                    }
                    throw ex;
                }
                return conn;
            }
        }
    }
}
